package top.xana.acg.music.ui.view

import android.content.Context
import android.graphics.Canvas
import android.util.AttributeSet
import android.view.LayoutInflater
import android.view.View
import android.widget.Adapter
import android.widget.FrameLayout
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import top.xana.acg.common.base.adp.RecyclerAdapter
import top.xana.acg.music.R

/**
 * Created by xana on 2022/3/25 0025
 * Describe: cv4096@qq.com
 */
class PlayListCardView @JvmOverloads constructor(
    context: Context,
    attrs: AttributeSet? = null,
    defStyleAttr: Int = 0,
    defStyleRes: Int = 0
) : FrameLayout(context, attrs, defStyleAttr, defStyleRes), View.OnClickListener,
    View.OnLongClickListener{


    val view by lazy {
        LayoutInflater.from(context).inflate(R.layout.view_play_list_card, this)
    }

    init {
        view.findViewById<TextView>(R.id.tv_operation).setOnClickListener(this)
        view.findViewById<View>(R.id.fl_bar).setOnClickListener(this)
    }
    val rvPlayList by lazy {
        view.findViewById<RecyclerView>(R.id.rv_play_list)
    }

    fun setAdapter(adp: RecyclerAdapter<*>) {
        rvPlayList.adapter = adp
    }

    private var cl: ClickListener? = null

    override fun onClick(p0: View){
        when(p0.id){
            R.id.tv_operation-> cl?.onOperationClick(p0 as TextView)
            else ->cl?.onPlayAllBarClick(p0)
        }
    }

    override fun onLongClick(p0: View?) = true

    interface ClickListener{
        fun onOperationClick(view: TextView)
        fun onPlayAllBarClick(view: View)
    }


    override fun onDraw(canvas: Canvas?) {
        super.onDraw(canvas)
    }

}